package net.kunyv.base.service;


import net.kunyv.base.entity.SysCompany;
import net.kunyv.base.entity.TVacation;
import net.kunyv.base.mapper.TVacationMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;

/**
 * 用户servcie
 *
 * @author sunyb
 * @date 2017-08-02
 */
@Service
public class TVacationService extends BaseService<TVacation> {
    @Autowired
    private TVacationMapper tVacationMapper;

    /**
     * 新增
     *
     * @param
     * @param
     * @return java.lang.String
     * @throw
     * @author sunyb
     * @date 2020/7/7
     */
    public String doAdd(TVacation tVacation) {
        System.out.println("------------------------------");
        System.out.println(tVacation.getId());
        System.out.println(tVacation.getUserId());
        System.out.println(tVacation.getApplyDate());
        System.out.println(tVacation.getBeginDate());
        System.out.println(tVacation.getEndDate());
        System.out.println(tVacation.getVacType());
        System.out.println(tVacation.getProcInstId());
        System.out.println(tVacation.getStatus());
        System.out.println(tVacation.getWorkDays());
        System.out.println(tVacation.getReason());
        System.out.println("--------------------");


            int i = tVacationMapper.insert(tVacation);
            if (i == 1) {
                return "ok";
            } else {
                return "新增失败";
            }
    }


    /**
     * 新增或编辑
     *
     * @param sysCompany
     * @param userId
     * @return java.lang.String
     * @throw
     * @author sunyb
     * @date 2020/7/7
     */
    public String save(TVacation tVacation, String userId) {
        Date now = new Date();

        if (StringUtils.isEmpty(tVacation.getId())) {
            Example example = new Example(SysCompany.class);
            Example.Criteria criteria = example.createCriteria();
            tVacation.setId(null);
            int i = tVacationMapper.insert(tVacation);
            if (i == 1) {
                return "ok";
            } else {
                return "新增失败";
            }
        } else {
            Example example = new Example(SysCompany.class);
            Example.Criteria criteria = example.createCriteria();
            int i = tVacationMapper.updateByPrimaryKeySelective(tVacation);
            if (i == 1) {
                return "ok";
            } else {
                return "更新失败";
            }

        }
    }

    /**
     * 修改
     *
     * @param
     * @param
     * @return java.lang.String
     * @throw
     * @author sunyb
     * @date 2020/7/7
     */
    public String doUpdate(TVacation sysCompany) {
        Date now = new Date();
            Example example = new Example(TVacation.class);
            Example.Criteria criteria = example.createCriteria();
            int i = tVacationMapper.updateByPrimaryKeySelective(sysCompany);
            if (i == 1) {
                return "ok";
            } else {
                return "更新失败";
            }

    }


}
